package com.yanqu.road.server.cmd.grandchild.exam;

import com.yanqu.road.pb.grandchild.GrandChildProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.grandchild.GrandChildConfigMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = GameProtocol.S_GRAND_CHILD_SYNC_EXAM_GROUP, desc = "同步科举分组区服")
public class SyncExamConfigFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        GrandChildConfigMgr.changeGroupConfig();
        GrandChildProto.GrandChildSyncExamGroupRespMsg req = GrandChildProto.GrandChildSyncExamGroupRespMsg.parseFrom(packet.getBytes());
        GrandChildProto.GrandChildSyncExamGroupRespMsg.Builder builder = req.toBuilder();
        for (GamePlayer gamePlayer : GamePlayerMgr.getCopyPlayerList()) {
            if (gamePlayer != null) {
                gamePlayer.sendPacket(ClientProtocol.U_GRAND_CHILD_SYNC_EXAM_GROUP, builder);
            }
        }
    }

}
